﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNVP.Framework;
using System.Data;
using CNVP.JShop.UI;
using CNVP.Framework.Helper;
using CNVP.Framework.Utils;

namespace CNVP.JShop.Web.Admin
{
    public partial class AdvanceAds : AdminPage
    {
        BLL.CNVP_Ads bll = new BLL.CNVP_Ads();
        public int rplistCount = 0;
        public int PageIndex = 1;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!BLL.BLLCheckAdmin.LoginOk(Page, 140)) return;//判断页面权限
            if (!string.IsNullOrEmpty(Request.QueryString["Page"]) && Public.IsNumber(Request.QueryString["Page"]))
            {
                PageIndex = Convert.ToInt32(Request.QueryString["Page"]);
            }
            if (!IsPostBack)
            {
                StartLoad(PageIndex);
                btDelete.Attributes.Add("onclick", "if(ifCheck()){return confirm('确定删除该记录吗?');}else{alert('请选择记录！');return false;};");
            }
        }

        /// <summary>
        /// PageNavigator1_PageChange 的摘要说明
        /// 分页加载列表函数
        /// </summary>
        protected void StartLoad(int PageIndex)
        {
            SQLConditionInfo[] st = new SQLConditionInfo[1];
            st[0] = new SQLConditionInfo("@AdClassID", "105");
            int i, j;
            DataTable dt = null;
            int pageNum = 20;
            dt = bll.GetAdvanceAds(PageIndex, pageNum, out i, out j, st);

            if (dt != null)
            {
                rplistCount = dt.Rows.Count;//行数
                //----------------------------------------添加列------------------------------------------------
                dt.Columns.Add("oID", typeof(string));
                dt.Columns.Add("oDisplay", typeof(string));
                dt.Columns.Add("oServerName", typeof(string));
                dt.Columns.Add("oLoginTitle", typeof(string));
                dt.Columns.Add("oOpenTime", typeof(string));
                dt.Columns.Add("oEdition", typeof(string));
                dt.Columns.Add("oIndexUrl", typeof(string));
                dt.Columns.Add("oPostTime", typeof(string));
                //----------------------------------------添加列结束--------------------------------------------
                for (int k = 0; dt.Rows.Count > k; k++)
                {
                    dt.Rows[k]["oID"] = dt.Rows[k]["ID"].ToString();

                    if (dt.Rows[k]["DisplayType"].ToString()=="0")
                    {
                        dt.Rows[k]["oDisplay"] = "套黄广告";
                    }
                    else if (dt.Rows[k]["DisplayType"].ToString() == "1")
                    {
                        dt.Rows[k]["oDisplay"] = "通宵固顶";
                    }
                    else if (dt.Rows[k]["DisplayType"].ToString() == "2")
                    {
                        dt.Rows[k]["oDisplay"] = "全天固定";
                    }
                    else if (dt.Rows[k]["DisplayType"].ToString() == "3")
                    {
                        dt.Rows[k]["oDisplay"] = "通宵广告";
                    }

                    
                    dt.Rows[k]["oServerName"] = dt.Rows[k]["ServerName"].ToString();
                    dt.Rows[k]["oLoginTitle"] =  dt.Rows[k]["DownLoadLink"].ToString();
                    dt.Rows[k]["oOpenTime"] = dt.Rows[k]["OpenTime"].ToString();
                    dt.Rows[k]["oEdition"] = dt.Rows[k]["EditionInfor"].ToString();
                    dt.Rows[k]["oIndexUrl"] = dt.Rows[k]["HomeLink"].ToString();
                    dt.Rows[k]["oPostTime"] =   Public.StampToDate(long.Parse(dt.Rows[k]["AdvanceTime"].ToString()));
                }
            }

            rpList.DataSource = dt;
            rpList.DataBind();
            paging.InnerHtml = Paginator.Pagination(PageIndex, i, j);
        }

        protected void btDelete_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.rpList.Items.Count; i++)
            {
                CheckBox cbCheck = (CheckBox)this.rpList.Items[i].FindControl("cbCheck");
                if (cbCheck.Checked == true)
                {
                    int code = int.Parse(cbCheck.ToolTip);
                    bll.Delete_CNVP_Ads(code);
                }
            }
            StartLoad(PageIndex);
        }
    }
}